package com.wisezone.demo0215;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class TestClint {
    public static void main(String[] args) {
        try{
            //服务端地址
            InetAddress inetServer = InetAddress.getByName("localhost");
            //服务器端口
            int port =5090;
            Socket socket = new Socket(inetServer,port);
            //发送消息给服务端
            OutputStream os = socket.getOutputStream();
            //接收服务端的消息
            InputStream is = socket.getInputStream();

            os.write("I love you".getBytes());
            os.flush();

            byte[] b = new byte[512];
            is.read(b);
            String str = new String(b);
            System.out.println(str);
            socket.close();
        }catch (UnknownHostException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
